/*author:Tony Tout
 *time:2013-03~2013-04
 *email:taotanty@gmail.com
 *the data is about channel data.
 *this is the main window for the program .in this class ,i save translate and tcl_usb.The former is save the tv file data.
 *the latter is save standard file data,which i define that.
 *the program starts convert tv file data to standard data,the we can edit the standard data.then we save the edited standard
 *file .at last we convert the standard to the tv file data.
 *we can use the edited file data to replace tv channe data.
 */

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include"tcl_mstar_dtv_tv.h"
#include"tcl_mtk_atv_tv.h"
#include"tcl_mtk_dtv_tv.h"
#include "tcl_usb.h"
#include "translate.h"
#include "md_atv.h"
#include "md_dtv.h"
//#include "thread.h"
#include<QFile>
#include<QDataStream>
#include <QStandardItemModel>
#include <QList>
#include<QStandardItem>
#include<QFileDialog>
#include <QDir>
#include <QMessageBox>
#include <QHeaderView>
#include <QStandardItem>
#include <dbt.h>
#include <windows.h>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
   // void on_DataTable_clicked(QModelIndex index);
    void Read_File();
    void Write_File();
    void open_file();
    void sortSlot(int);
    void Show_ATV();
    void Show_DTV();
    void Del_Row( );
    void Mod_ATV_std();
    void Mod_DTV_std();
    void Show_Menu(QPoint);
    void Md_Data();

    void Do_Md(TCL_MSTAR_ATV_TV);
    void Do_Md(TCL_MSTAR_DTV_TV);
    void Do_Md(TCL_MTK_ATV_TV);
    void Do_Md(TCL_MTK_DTV_TV);
   // void Do_Md(TCL_MTK_ATV_TV);

  //  void DataChanged(QStandardItem *);
    void Con_std_file();
    void Con_tv_file();
    void set_cur_row(QModelIndex);
    void set_cur_show(int);
    void LastPage();
    void NextPage();
private:
    Ui::MainWindow *ui;
    QMenu *cmenu;
    bool ch_is_exist;//表示频道文件的存在
    bool sortFlag;//排序方式，用来表示顺序还是逆序
    bool is_atv_edit;
    bool is_dtv_edit;
    bool save_atv_edit;
    bool save_dtv_edit;
    bool modify;//为了避免在初始生成表格时，触发DataChanged()中的修改动作

    //Init at Init() Function,set at NextPage() and LastPage().
    int cur_atv_loc;
    int cur_dtv_loc;
    QList<QStandardItem *> Get_Item_Row(TCL_MSTAR_ATV_TV* mstar_atv_tv);
    QList<QStandardItem *> Get_Item_Row(TCL_MSTAR_DTV_TV* mstar_dtv_tv);
    QList<QStandardItem *> Get_Item_Row(TCL_MTK_ATV_TV* mtk_atv_tv);
    QList<QStandardItem *> Get_Item_Row(TCL_MTK_DTV_TV* mtk_dtv_tv);
    void Refresh();
    void Init();
    char FirstDriveFromMask (ULONG unitmask);

    int count_col_atv;
    int count_col_dtv;

    int cur_show;//0-mtk_atv,1-mtk_dtv,2-mstar_atv,3-mstar_dtv,Init at Read_File(),then set at set_cur_show()
    int cur_row;

    TCL_USB *tcl_usb;
    MSTAR_TV *ms_tv;
    QList<QString >head_data;
    QStandardItemModel *model_atv;
    QStandardItemModel *model_dtv;
    QString read_file_name;
    QString write_file_name;
    int Find_List_Row();
    int Find_List_Row(int);
protected:
    bool winEventFilter(MSG *msg);

};

#endif // MAINWINDOW_H
